package com.zwk.views;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import com.zwk.model.WKTchOperator;

public class WKResetTchMsgView {

	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 350;
	private static final int DEFAULT_HEIGHT = 350;
	public static JFrame frame;
	JFrame parentFrame;
	public WKResetTchMsgView(String id) {
		frame = new JFrame();
		frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		frame.setTitle("教师个人信息修改");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenWidthpx = screenSize.width;
		int screenHeightpx = screenSize.height;
		frame.setLocation(screenWidthpx / 3, screenHeightpx / 3);
		frame.setLocationByPlatform(false);
		
		Image image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg")).getImage();
		frame.setIconImage(image);
		WKResetTchMsgPanel loginPanel = new WKResetTchMsgPanel(id);
		frame.setContentPane(loginPanel);
		frame.setLayout(null);
		frame.setVisible(true);
		
	}
	private class WKResetTchMsgPanel extends JPanel {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		JPanel stuPanel;
		JLabel nameLabel;
	    JTextField nameTextField;
	    JLabel numLabel;
	    JTextField numTextField;
	    JLabel schLabel;
	    JComboBox schComboBox;
	    JLabel majorLabel;
	    JComboBox majorComboBox;
	    JLabel mailLabel;
	    JTextField mailTextField;
	    
	    JPanel pictruePanel;
	    JLabel tipLabel;
	    JLabel picLabel;
	    JButton resetButton;
	    
	
	    
	    JPanel funcPanel;
	    JButton resetMailButton;
	    JButton backButton;
	    
	    public WKResetTchMsgPanel(final String id) {
	    	final WKTchOperator OP = new WKTchOperator();
	    	OP.getInfo(id);
	    	//属性部分
	    	stuPanel = new JPanel();
	    	stuPanel.setBounds(0, 0, 160, 300);
	    	stuPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
	    	nameLabel = new JLabel("姓名");
		    nameTextField = new JTextField(OP.teacher.getName(), 12);
		    nameTextField.setEditable(false);
		    numLabel = new JLabel("学号");
		    numTextField = new JTextField(id, 12);
		    numTextField.setEditable(false);
		    schLabel = new JLabel("所属学院");
		    DefaultComboBoxModel sch = new DefaultComboBoxModel();
		    sch.addElement("软件工程学院");
		    sch.addElement("通信学院");
		    schComboBox = new JComboBox(sch);
		    schComboBox.setSelectedItem(OP.teacher.getCollege());;
		    majorLabel = new JLabel("所属教研室");
		    DefaultComboBoxModel major = new DefaultComboBoxModel();
		    major.addElement("软件实验中心");
		    major.addElement("数字媒体研究所");
		    majorComboBox = new JComboBox(major);
		    majorComboBox.setSelectedItem(OP.teacher.getFacuilty());
		    mailLabel = new JLabel("电子邮箱");
		    mailTextField = new JTextField(OP.teacher.getEmail(), 12);
		    
		    stuPanel.add(nameLabel);
		    stuPanel.add(nameTextField);
		    stuPanel.add(numLabel);
		    stuPanel.add(numTextField);
		    stuPanel.add(schLabel);
		    stuPanel.add(schComboBox);
		    stuPanel.add(majorLabel);
		    stuPanel.add(majorComboBox);
		    stuPanel.add(mailLabel);
		    stuPanel.add(mailTextField);
	    	add(stuPanel);
	    	
	    	//头像部分
	    	pictruePanel = new JPanel();
	    	pictruePanel.setBounds(200, 0, 140, 180);
	    	pictruePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
	    	picLabel = new JLabel();
	    	picLabel.setSize(150, 100);
	    	ImageIcon image = new ImageIcon(this.getClass().getResource("/WKImage/header.jpg"));
	    	image.setImage(image.getImage().getScaledInstance(picLabel.getWidth(), picLabel.getHeight(), Image.SCALE_DEFAULT));;
	    	picLabel.setIcon(image);
	    	tipLabel = new JLabel("个人照片");
	    	resetButton = new JButton("修改个人照片");
	    	
	    	pictruePanel.add(tipLabel);
	    	pictruePanel.add(picLabel);
	    	pictruePanel.add(resetButton);
	    	add(pictruePanel);
	       
	    	//修改数据
	    	funcPanel = new JPanel();
	    	funcPanel.setBounds(0, 290, 350, 40);
	    	funcPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
	    	resetMailButton = new JButton("确认修改");
	    	resetMailButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			OP.teacher.setCollege((String)schComboBox.getSelectedItem());
	    			OP.teacher.setFacuilty((String)majorComboBox.getSelectedItem());
	    			OP.teacher.setEmail(mailTextField.getText());
	    			OP.resetTch(OP.teacher);
	    			JOptionPane.showMessageDialog(null, "修改信息成功", "修改成功", JOptionPane.OK_OPTION);
	    		}
	    	});
	    	backButton = new JButton("返回上级菜单");
	    	backButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKTchFuncPortalFrame stdView = new WKTchFuncPortalFrame(id);
	    			frame.dispose();
	    		}
	    	});
	    	funcPanel.add(resetMailButton);
	    	funcPanel.add(backButton);
	    	add(funcPanel, BorderLayout.SOUTH);
	    
	    }
	
	}
}